<?php

namespace App\Http\Requests\Admin\Customer\Brand;

use App\Exceptions\ApiErrCode;
use App\Exceptions\ApiException;
use App\Http\Requests\ApiRequest;
use App\Models\Panx\Brand;
use App\Services\Utils\Guard;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string url
 * @property string sort
 * @property string logo
 */
class ProductBrandStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $customer_id = Guard::customerAdmin()->customer_id;

        $data = [
            'name' => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('brands', 'name')->where(function($query) use($customer_id){
                return $query->where('customer_id', $customer_id);
            })],
            'url'  => 'nullable|url|max:'.self::MAX_STRING,
            'logo' => 'required|file|max:2048',
            'sort' => 'required|int'
        ];

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.unique' => '品牌名称必须唯一，数据库中已有同名品牌',
//            'name.*'      => '品牌名称必须是字符串, 且必须不能重复',
//            'url.*'       => '品牌url必须是合法网址',
//            'logo.*'      => '品牌logo必须是小于2M的图片',
//        ];
//    }
}
